package com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.commandtype;

import com.zx.idc.backend.gui.api.commom.entity.CommandModel;
import com.zx.idc.backend.gui.api.management.accesslog.logquery.service.LogQueryService;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.base.CommandOperating;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.base.CommandType;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.entity.Option;
import com.zx.idc.xml.entity.logquery.LogQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import static com.zx.idc.common.attributes.SchemaFileNameAttributes.ACCESS_LOG_QUERY;

/**
 * Created by hasee on 2019/2/21.
 * 访问日志查询指令 11.5
 */
@Component
@Transactional(rollbackFor = Exception.class)
public class AccessLogQueryImpl extends CommandOperating<LogQuery> implements CommandType {

    private static final int num = 1;

    @Autowired
    private LogQueryService logQueryService;

    @Override
    public boolean isMatch(Option option) {
        return option.getType() == num;
    }

    @Override
    public String execute(String xmlData, CommandModel commandModel) {
        return receiveCommand(xmlData, commandModel, getSchemaFilePath(ACCESS_LOG_QUERY));
    }

    @Override
    public void task(LogQuery logQuery, CommandModel commandModel) {
        logQueryService.logQuery(logQuery, commandModel);
    }
}
